package Threading;

class MyRunnable implements  Runnable{
    @Override
    public void run() {
        while(true){
            System.out.println("==============Thread===============");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }


    }
}

// 通过重写 Runnable 来实现创建线程
public class Demo3 {
    public static void main(String[] args) {
        //把要做的事和线程分开写----减低了耦合性
        MyRunnable myRunnable=new MyRunnable();
        //一个线程
        Thread thread1=new Thread(myRunnable);
        thread1.start();

        //另一个线程
        Thread thread2=new Thread(myRunnable);    //2个线程都做同样的事，类似 多个售票窗口---提高效率
        thread2.start();

        while(true){
            System.out.println("main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }




    }
}
